/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package test.coalescent.data;

import coalescent.data.K69Data;
import coalescent.model.K69;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author Susanta Tewari
 * @since May 26, 2011
 */
public class K69TestData {

    public static final Map<String, K69Data> heinDataSets               = new HashMap<>();
    public static final Map<String, K69> models                         = new HashMap<>();
    public static final Map<String, Double> heinProbs                   = new HashMap<>();
    public static final Map<String, Map<Double, Double>> heinMultiProbs = new HashMap<>();
    public static final Map<String, K69Data> johnDataSet                = new HashMap<>();
    public static final Map<String, Double> johnProbs                   = new HashMap<>();
    public static final Map<String, K69Data> tewariDataSets             = new HashMap<>();
    public static final Map<String, Double> tewariProbs                 = new HashMap<>();

    /** Hein Data Sets */
    static {


        // put the hein data set
        // D-2-2
        heinDataSets.put("D-2-2", new K69Data(1.0, new String[] { "a1", "a2" }, new String[] { "1",
                "0" }, new String[] { "1", "1" }));


        // D-3-1
        heinDataSets.put("D-3-1", new K69Data(1.0, new String[] { "a1", "a2" }, new String[] { "1",
                "0" }, new String[] { "1", "2" }));


        // D-3-2
        heinDataSets.put("D-3-2", new K69Data(1.0, new String[] { "a1", "a2" }, new String[] { "11",
                "00" }, new String[] { "1", "1" }));


        // D-3-3
        heinDataSets.put("D-3-3", new K69Data(1.0, new String[] { "a1", "a2" }, new String[] { "1",
                "0" }, new String[] { "2", "1" }));


        // D-4-1
        heinDataSets.put("D-4-1", new K69Data(1.0, new String[] { "a1", "a2" }, new String[] { "11",
                "00" }, new String[] { "1", "2" }));


        // D-4-2
        heinDataSets.put("D-4-2",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3" }, new String[] { "10",
                "01", "00" }, new String[] { "1", "1", "1" }));


        // D-4-3
        heinDataSets.put("D-4-3", new K69Data(1.0, new String[] { "a1", "a2" }, new String[] { "1",
                "0" }, new String[] { "2", "2" }));


        // D-4-4
        heinDataSets.put("D-4-4", new K69Data(1.0, new String[] { "a1", "a2" }, new String[] { "11",
                "00" }, new String[] { "2", "1" }));


        // D-5-1
        heinDataSets.put("D-5-1",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3" }, new String[] { "110",
                "001", "000" }, new String[] { "1", "1", "1" }));


        // D-5-2
        heinDataSets.put("D-5-2",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3" }, new String[] { "10",
                "01", "00" }, new String[] { "1", "2", "1" }));


        // D-5-3
        heinDataSets.put("D-5-3", new K69Data(1.0, new String[] { "a1", "a2" }, new String[] { "11",
                "00" }, new String[] { "2", "2" }));


        // D-5-4
        heinDataSets.put("D-5-4",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3" }, new String[] { "110",
                "111", "000" }, new String[] { "1", "1", "1" }));


        // D-6-1
        heinDataSets.put("D-6-1",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3" }, new String[] { "110",
                "001", "000" }, new String[] { "1", "2", "1" }));


        // D-6-2
        heinDataSets.put("D-6-2",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3" }, new String[] { "110",
                "001", "000" }, new String[] { "2", "1", "1" }));


        // D-6-3
        heinDataSets.put("D-6-3",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3" }, new String[] { "110",
                "111", "000" }, new String[] { "1", "1", "2" }));


        // D-7-1
        heinDataSets.put("D-7-1",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3" }, new String[] { "110",
                "001", "000" }, new String[] { "2", "2", "1" }));


        // D-7-2
        heinDataSets.put("D-7-2",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3", "a4" },
                                     new String[] { "1100",
                "1110", "0001", "0000" }, new String[] { "1", "1", "1", "1" }));


        // D-8-1
        heinDataSets.put("D-8-1",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3", "a4" },
                                     new String[] { "1100",
                "1110", "0000", "0001" }, new String[] { "1", "1", "1", "2" }));


        // gt94-1
        heinDataSets.put("gt94-1", new K69Data(1.0, new String[] {
            "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", "a12", "a13", "a14"
        }, new String[] {

            "100101000000010000", "100101000100010000", "010000000000000001", "001000001000000000",
            "000101000000010000", "000111000000010000", "000000000011000001", "000000000011100001",
            "000000000000000111", "000000000000000101", "000000000000000000", "000000000000000001",
            "000000010000000000", "000000100000001000"

        }, new String[] {
            "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"
        }));


        // 5-4-f2
        heinDataSets.put("D-5-4-f2",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3" }, new String[] { "110",
                "111", "000" }, new String[] { "2", "2", "2" }));


        // 8-1-f2
        heinDataSets.put("D-8-1-f2",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3", "a4" },
                                     new String[] { "1100",
                "1110", "0001", "0000" }, new String[] { "2", "2", "2", "2" }));


        // 8-1-f3
        heinDataSets.put("D-8-1-f3",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3", "a4" },
                                     new String[] { "1100",
                "1110", "0001", "0000" }, new String[] { "3", "3", "3", "3" }));


        // 8-1-f4
        heinDataSets.put("D-8-1-f4",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3", "a4" },
                                     new String[] { "1100",
                "1110", "0001", "0000" }, new String[] { "4", "4", "4", "4" }));


        // gt94-1-1
        heinDataSets.put("gt94-1-1",
                         new K69Data(1.0, new String[] { "a1", "a2", "a3", "a4" },
                                     new String[] { "100",
                "110", "101", "000" }, new String[] { "1", "2", "2", "2" }));
    }

    /** K69 Models */
    static {

        models.put("M-0.5", new K69(0.5));
        models.put("M-1.0", new K69(1.0));
        models.put("M-2.0", new K69(2.0));
        models.put("M-3.0", new K69(3.0));
        models.put("M-4.0", new K69(4.0));
        models.put("M-5.0", new K69(5.0));
    }

    /** Hein Data Sets Probabilities */
    static {

        heinProbs.put("D-2-2", 1.0 / 4);
        heinProbs.put("D-3-1", 7.0 / 36);
        heinProbs.put("D-3-2", 1.0 / 16);
        heinProbs.put("D-3-3", 1.0 / 12);
        heinProbs.put("D-4-1", 55.0 / 1296);
        heinProbs.put("D-4-2", 7.0 / 81);
        heinProbs.put("D-4-3", 10.0 / 144);
        heinProbs.put("D-4-4", 1.0 / 48);
        heinProbs.put("D-5-1", 37.0 / 1944);
        heinProbs.put("D-5-2", 157.0 / 5184);
        heinProbs.put("D-5-3", 41.0 / 2592);
        heinProbs.put("D-5-4", 1.0 / 216);
        heinProbs.put("D-6-1", 3310.0 / 497664);
        heinProbs.put("D-6-2", 419.0 / 62208);
        heinProbs.put("D-6-3", 65.0 / 20736);
        heinProbs.put("D-7-1", 6662.0 / 2488320);
        heinProbs.put("D-7-2", 307.0 / 248832);
        heinProbs.put("D-8-1", 14337.0 / 31104000);
        heinProbs.put("gt94-1", 2.8005E-19);
    }

    /** Hein Data Sets Multi-Theta-Probabilities */
    static {

        heinMultiProbs.put("D-8-1",
                           ImmutableMap.of(1.0, 4.6094E-4, 2.0, 7.6968E-4, 3.0, 6.9054E-4));
    }

    /** John Data Sets */
    static {


        // J-1
        johnDataSet.put("J-1", new K69Data(1.0, new String[] { "a1", "a2" }, new String[] { "110",
                "001" }, new String[] { "2", "2" }));


        // J-2
        johnDataSet.put("J-2", new K69Data(1.0, new String[] { "a1", "a2" }, new String[] { "1",
                "0" }, new String[] { "3", "2" }));


        // J-3
        johnDataSet.put("J-3", new K69Data(1.0, new String[] { "a1", "a2" }, new String[] { "1",
                "0" }, new String[] { "3", "3" }));
    }

    /** John Data Sets Probabilities */
    static {

        johnProbs.put("J-1", 305.0 / 31104);
        johnProbs.put("J-2", 26.0 / 720);
        johnProbs.put("J-3", 552.0 / 17280);
    }

    /** Tewari Data Sets */
    static {


        // T-1
        tewariDataSets.put("T-1",
                           new K69Data(1.0, new String[] { "a1", "a2", "a3", "a4", "a5" },
                                       new String[] { "11000",
                "11100", "11010", "00001", "00000" }, new String[] { "2", "1", "1", "2", "1" }));


        // T-2
        tewariDataSets.put("T-2", new K69Data(1.0, new String[] {
            "a1", "a2", "a3", "a4", "a5", "a6"
        }, new String[] {
            "1100000", "1110000", "0001100", "0001110", "0000001", "0000000"
        }, new String[] {
            "1", "1", "1", "1", "2", "1"
        }));


        // T-3
        tewariDataSets.put("T-3",
                           new K69Data(1.0, new String[] { "a1", "a2", "a3" },
                                       new String[] { "1100",
                "0011", "0000" }, new String[] { "2", "1", "1" }));
    }

    /** Tewari Data Sets Probabilities */
    static {

        tewariProbs.put("T-1", 6.2764E-5);
        tewariProbs.put("T-2", 1.1931E-6);
        tewariProbs.put("T-3", 0.0014783513017261082);
    }

    private K69TestData() {}

    /**
     * @return data keys in {@code heinDataSets} that have probability values and
     * the size is suitable for testing.
     */
    public static Set<String> of_hein_withProb_test() {

        Set<String> result = ImmutableSet.copyOf(new String[] {

            "D-2-2", "D-3-1", "D-3-2", "D-3-3", "D-4-1", "D-4-2", "D-4-3", "D-4-4", "D-5-1",
            "D-5-2", "D-5-3", "D-5-4", "D-6-1", "D-6-2", "D-6-3", "D-7-1", "D-7-2", "D-8-1"

        });

        return result;
    }
}
